package 常用api;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import static java.math.BigDecimal.ROUND_HALF_UP;

public class bigdecimal {
    public static void main(String[] args) {
        System.out.println(0.1+0.2);
        System.out.println(new BigDecimal("0.1").add(new BigDecimal("0.2")));
        System.out.println(BigDecimal.valueOf(0.1).add(BigDecimal.valueOf(0.2)));
        System.out.println(BigDecimal.valueOf(0.1).multiply(BigDecimal.valueOf(0.2)));
        System.out.println(BigDecimal.valueOf(0.1).divide(BigDecimal.valueOf(0.3), ROUND_HALF_UP,3));
// 保留3位小数输出
        System.out.println(new DecimalFormat("#.##").format(1/3.0));
    }
}
